﻿
using CSharpLibs.Annotations;

namespace System
{
	[Builtin]
	public struct Nullable<T0> where T0: struct
	{
		private bool hasValue;
		internal T0 value;

		public Nullable(T0 value)
		{
			this.value = value;
			this.hasValue = true;
		}

		public bool HasValue
		{get { return this.hasValue; } }

		public T0 Value
		{
			get
			{
				if(!this.hasValue)
					Environment.Exit(1);

				return this.value;
			}
		}
		
		public override bool Equals(object other)
		{
			if(!this.HasValue)
			{
				return (other == null);
			}
			if(other == null)
			{
				return false;
			}
			return this.value.Equals(other);
		}

		public override int GetHashCode()
		{
			if(!this.HasValue)
			{
				return 0;
			}
			return this.value.GetHashCode();
		}

		public override string ToString()
		{
			if(!this.HasValue)
			{
				return String.Empty;
			}

			return this.value.ToString();
		}
	}
}
